package com.bigegg.employee.api;

import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.bigegg.employee.util.CommonUtil;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.bigegg.employee.domain.Graduate;
import com.bigegg.employee.service.IGraduateService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 毕业生管理Controller
 * 
 * @author 刘博
 * @date 2022-08-11
 */
@RestController
@RequestMapping("/employee/graduate")
public class GraduateController extends BaseController
{
    @Autowired
    private IGraduateService graduateService;

    /**
     * 查询毕业生管理列表
     */
    @PreAuthorize("@ss.hasPermi('employee:graduate:list')")
    @GetMapping("/list")
    public TableDataInfo list(Graduate graduate)
    {
        startPage();
        List<Graduate> list = graduateService.selectGraduateList(graduate);
        return getDataTable(list);
    }

    /**
     * 导出毕业生管理列表
     */
    @PreAuthorize("@ss.hasPermi('employee:graduate:export')")
    @Log(title = "毕业生管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Graduate graduate)
    {
        List<Graduate> list = graduateService.selectGraduateList(graduate);
        ExcelUtil<Graduate> util = new ExcelUtil<Graduate>(Graduate.class);
        util.exportExcel(response, list, "毕业生管理数据");
    }

    /**
     * 获取毕业生管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('employee:graduate:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(graduateService.selectGraduateById(id));
    }

    /**
     * 新增毕业生管理
     */
    @PreAuthorize("@ss.hasPermi('employee:graduate:add')")
    @Log(title = "毕业生管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Graduate graduate)
    {
        return toAjax(graduateService.insertGraduate(graduate));
    }

    /**
     * 修改毕业生管理
     */
    @PreAuthorize("@ss.hasPermi('employee:graduate:edit')")
    @Log(title = "毕业生管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Graduate graduate)
    {
        return toAjax(graduateService.updateGraduate(graduate));
    }

    /**
     * 删除毕业生管理
     */
    @PreAuthorize("@ss.hasPermi('employee:graduate:remove')")
    @Log(title = "毕业生管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(graduateService.deleteGraduateByIds(ids));
    }

    /**
     * 上传excel
     */
    @PostMapping("/importData")
    public AjaxResult importData(@RequestParam("file") MultipartFile file)
    {

        this.graduateService.importData(file);
        return AjaxResult.success();
    }

    /**
     * 下载模板
     */
    @PostMapping("/downloadTpl")
    public void downloadTpl(HttpServletRequest request, HttpServletResponse response)
    {

        // 模板的路径
        String tplPath = "tpl/毕业生导入模板.xlsx";

        CommonUtil.downloadResource(tplPath,response);

    }
}
